package com.hurl.waguji.biz.download;

import com.hurl.library.spider.SpiderException;
import com.hurl.library.spider.UrlPattern;
import com.hurl.library.util.DateUtils;
import com.hurl.library.util.StringUtils;
import com.hurl.waguji.base.Formatter;
import com.hurl.waguji.base.dataprocess.ProcessParams;
import com.hurl.waguji.persistence.DmGpBO;
import com.hurl.waguji.persistence.JcsjCwCwblHexunBO;
import com.hurl.waguji.persistence.JcsjCwCwblHexunBOId;

class CwCwblHexunProcessor extends BaseDownloadForUpdateProcessor{
	


	public CwCwblHexunProcessor(ProcessParams params,
			DownloadIdentifier identifier) {
		super(params, identifier);
	}
	private JcsjCwCwblHexunBO html2BO(String gpdm, String html) throws SpiderException {
		if(StringUtils.isBlank(html)){
			return null;
		}
		html = StringUtils.substringBetween(html, "<span id=\"ControlEx1_lbl\">", "</span>");
		if(StringUtils.isBlank(html)){
			return null;
		}
		JcsjCwCwblHexunBO bo = new JcsjCwCwblHexunBO();
		
		String tmp = StringUtils.substringBetween(html, "会计年度", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setId(new JcsjCwCwblHexunBOId(gpdm,Formatter.toDate(tmp)));
		
		tmp = StringUtils.substringBetween(html, "流动比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setLdbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "速动比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setSdbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "现金比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setXjbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "权益负债比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setQyfzbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "长期资产适合率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setCqzcshl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "流动资产对负债总额比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setLdzcdfzzebl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "有息负债率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setYxfzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "不良债权比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setBlzqbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "存货流动负债比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setChldfzbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "债务偿付比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZwcfbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "负债结构比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setFzjgbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "坏帐备抵率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setHzbdl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "固定支出成本占总成本的比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setGdzccbzzcbbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "利息支付倍数", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setLxzfbs(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "固定财务费用保付率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setGdcwfybfl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "清算价值比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setQsjzbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "营运资产与总资产的比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setYyzcyzzcbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "现金与总资产的比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setXjyzzcbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "净资产收益率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setJzcsyl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "总资产收益率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZzcsyl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "资本金收益率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZbjsyl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "主营业务利润率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZyywlrl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "主营收入毛利润率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZysrmlrl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "主营收入税前利润率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZysrsqlrl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "主营收入税后利润率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZysrshlrl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "扣除非经常损益后的净利润率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setKcfjcsyhjlrl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "营业利润率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setYylrl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "营业比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setYybl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "成本费用利润率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setCbfylrl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "销售期间费用率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setXsqjfyl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "非经常性损益比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setFjcxsybl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "关联交易比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setGljybl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "本期股利收益率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setBqglsyl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "股利支付比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setGlzfbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "收益留存比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setSylcbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "应收帐款周转率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setYszkzzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "应收帐款回收期", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setYszkhsq(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "流动资产周转率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setLdzczzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "固定资产周转率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setGdzczzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "存货周转率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setChzzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "存货销售期", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setChxsq(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "总资产周转率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZzczzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "净资产周转率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setJzczzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "主营利润比重", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZylrbz(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "流动资产对总资产的比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setLdzcdzzcbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "资产负债率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZcfzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "资本化比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZbhbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "资本固定化比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZbgdhbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "资本周转率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZbzzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "固定资产与长期负债率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setGdzcycqfzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, ">固定资产与股东权益比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setGdzcygdqybl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "固定资产净值率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setGdzcjzl(Formatter.toDouble(tmp)/100);
		
		tmp = StringUtils.substringBetween(html, "权益系数", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setQyxs(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "长期负债比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setCqfzbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "产权比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setCqbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "净值与负债比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setJzyfzbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "净值与固定资产比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setJzygdzcbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "有形资产净值债务率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setYxzcjzzwl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, ">股东权益比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setGdqybl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "主营业务增长率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZyywzzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "应收款项增长率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setYskxzzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "净利润增长率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setJlrzzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "固定资产投资扩张率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setGdzctzkzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "总资产扩张率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZzckzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, ">每股收益增长率<", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setMgsyzzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "净资产增长率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setJzczhzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "每股经营现金净流量", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setMgjyxjjll(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "资产的经营现金流量回报率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZcjyxjllhbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "净利润现金含量", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setJlrxjhl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "经营现金净流量对负债的比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setJyxjjlldfzbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "经营活动产生的现金净流量增长率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setXjjllzzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "营业活动收益质量", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setJyhdsyzl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "主营业务现金比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setZyywxjbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "现金流量结构比率", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setXjlljgbl(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "每股净资产", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setMgjzc(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "调整后每股净资产", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setTzhmgjzc(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, ">每股收益<", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setMgsy(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, ">扣除非经常损益的每股收益<", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setKcfjcsymgsy(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "每股主营收入", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setMgzysr(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "每股经营活动产生的现金流量净额", "<tr>");
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setMgxjllje(Formatter.toDouble(tmp));
		
		tmp = StringUtils.substringBetween(html, "每股资本公积", null);
		tmp = StringUtils.substringBetween(tmp, "class='tishi'>", "</div>");
		bo.setMgzbgj(Formatter.toDouble(tmp));
		
		bo.setLastupdate(currentTime);
		
		return bo;
	}
	@Override
	public void convertHTML2BO(String url, String html, BOSaver collector) {

		if(StringUtils.isBlank(html)){
			return;
		}

		JcsjCwCwblHexunBO bo;
		try {
			bo = html2BO(context.getEnvAsString("gpdm"),html);
			if(bo!=null){
				collector.addBO(bo);
			}
		} catch (SpiderException e) {
			e.printStackTrace();
			context.setStopWithError(e);
		}
	}


	@Override
	public UrlPattern getUrlPattern() {
		return new StockIteratorUrlPattern(context) {
			
			@Override
			public String bo2url(DmGpBO bo) {
				String dateStr = DateUtils.formatDate(getRq(), "yyyy.MM.dd");
				return "http://stockdata.stock.hexun.com/2008/cwbl.aspx?stockid="+bo.getGpDmJ()+"&accountdate="+dateStr;
			}
		};
	}
}
